import Vue from 'vue'
import VueRouter from 'vue-router'
import recommend from '../views/recommend.vue'

Vue.use(VueRouter)

const routes = [
  {
    path:"/",
    redirect:"/recommend"
  },
  {
    path:"/my",
    name:"my",
    component:()=>import("../views/my.vue"),
    beforeEnter:(to,from,next)=>{
      let login = window.localStorage.getItem("token");
      // 判断没有值
      if(!login){
        next("/login");
        return;
      }else{
        next();
      }
    }
  },
  {
    path:"/login",
    name:"login",
    component:()=>import("../components/base/login.vue")
  },
  {
    path:"/recommend",
    name:"recommend",
    component:recommend,
  },
  {
    path:"/singer",
    name:"singer",
    component:()=>import("../views/singer.vue")
  },
  {
    path:"/rank",
    name:"rank",
    component:()=>import("../views/rank.vue")
  },
  {
    path:"/rank/ranklist",
    name:"ranklist",
    component:()=>import("../components/rank/ranklist.vue")
  },
  {
    path:"/search",
    name:"search",
    component:()=>import("../views/search.vue"),
    meta:{
      keepAlive:true
    }
  },
  {
    path:"/songlists",
    name:"songlists",
    component:()=>import("../views/songlists.vue"),
  },
  {
    path:"/more",
    name:"more",
    component:()=>import("../views/more/more.vue")
  },
  {
    path:"/MV",
    name:"MV",
    component:()=>import("../views/MV/MV.vue")
  },
  {
    path:"/singersong",
    name:"singersong",
    component:()=>import("../views/singersong.vue")
  },
  {
    path:"/rank/remarkLists",
    name:"remarkLists",
    component:()=>import("../components/rank/remarkLists.vue")
  },
  {
    path:"/rank/mysonglists",
    name:"mysonglists",
    component:()=>import("../components/rank/mysonglists.vue")
  },
  {
    path:"/my/myAttention",
    name:"myAttention",
    component:()=>import("../components/my/myAttention.vue")
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
